import java.io.*;

/**
 * @author zyj
 * @date 2022年05月30日 10:53
 */
public class ObjectOutputStreamDemo {
    public static void main(String[] args) {
        ObjectOutputStream oos = null;
        OutputStream os = null;

        try {
            os = new FileOutputStream("b.txt");
            oos = new ObjectOutputStream(os);
            oos.writeObject(new Student(1,"张三","admin","123456"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                oos.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }

}

class Student implements Serializable{
    private static final long serialVersionUID = 0L;
    private int id;
    private String name;
    private transient String userName;
    private transient String password;

    public Student(int id, String name, String userName, String password) {
        this.id = id;
        this.name = name;
        this.userName = userName;
        this.password = password;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
